﻿using Paltop_.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;

namespace PaltopTests
{


    /// <summary>
    ///This is a test class for UserControlerTest and is intended
    ///to contain all UserControlerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UserControlerTest
    {


        private TestContext testContextInstance;
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for CheckMailAvailebility
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void CheckMailAvailebilityTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string mail = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            int expected = -1; // TODO: Initialize to an appropriate value
            int actual;
            actual = target.CheckMailAvailebility(mail);
            Assert.AreEqual(expected, actual);
            mail = "newmail@mail.com";
            expected = 1;
            actual = target.CheckMailAvailebility(mail);
            Assert.AreEqual(expected, actual);
            mail = "newmail@m";
            expected = -10;
            actual = target.CheckMailAvailebility(mail);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for LoginCheck
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void LoginCheckTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string userName = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            string password = target.PasswordHassher("worngpassword"); // TODO: Initialize to an appropriate value
            int expected = -1; // TODO: Initialize to an appropriate value
            int actual;
            actual = target.LoginCheck(userName, password);
            Assert.AreEqual(expected, actual);
            userName = "wrong@gmail.com"; // TODO: Initialize to an appropriate value
            password = target.PasswordHassher("worngpassword"); // TODO: Initialize to an appropriate value
            expected = -2; // TODO: Initialize to an appropriate value
            actual = target.LoginCheck(userName, password);
            Assert.AreEqual(expected, actual);
            userName = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            password = target.PasswordHassher("onlygod@"); // TODO: Initialize to an appropriate value
            expected = -1; // TODO: Initialize to an appropriate value
            actual = target.LoginCheck(userName, password);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for UserControler Constructor
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void UserControlerConstructorTest()
        {
            UserControler target = new UserControler();
        }


        /// <summary>
        ///A test for ForgetPassword
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        public void ForgetPasswordTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string email = string.Empty; // TODO: Initialize to an appropriate value
            int expected = 0; // TODO: Initialize to an appropriate value
            int actual;
            actual = target.ForgetPassword(email);
            Assert.AreEqual(expected, actual);

        }


        /// <summary>
        ///A test for MailVarifier
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void MailVarifierTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string mail = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.MailVarifier(mail);
            Assert.AreEqual(expected, actual);
            mail = "amirpouya.a@gmail"; // TODO: Initialize to an appropriate value
            expected = false; // TODO: Initialize to an appropriate value
            actual = target.MailVarifier(mail);
            Assert.AreEqual(expected, actual);

            mail = "amirpouya.a@.com"; // TODO: Initialize to an appropriate value
            expected = false; // TODO: Initialize to an appropriate value
            actual = target.MailVarifier(mail);
            Assert.AreEqual(expected, actual);

            mail = ""; // TODO: Initialize to an appropriate value
            expected = false; // TODO: Initialize to an appropriate value
            actual = target.MailVarifier(mail);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for NameVarifier
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void NameVarifierTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string name = ""; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.NameVarifier(name);
            Assert.AreEqual(expected, actual);
            name = "a"; // TODO: Initialize to an appropriate value
            expected = false; // TODO: Initialize to an appropriate value
            actual = target.NameVarifier(name);
            Assert.AreEqual(expected, actual);
            name = "aaa"; // TODO: Initialize to an appropriate value
            expected = true; // TODO: Initialize to an appropriate value
            actual = target.NameVarifier(name);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for PasswordVarifier
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void PasswordVarifierTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string pass = ""; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.PasswordVarifier(pass);
            Assert.AreEqual(expected, actual);

            pass = "12345"; // TODO: Initialize to an appropriate value
            expected = false; // TODO: Initialize to an appropriate value
            actual = target.PasswordVarifier(pass);
            Assert.AreEqual(expected, actual);

            pass = "123456"; // TODO: Initialize to an appropriate value
            expected = true; // TODO: Initialize to an appropriate value
            actual = target.PasswordVarifier(pass);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///A test for RegisterNewAccount
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void RegisterNewAccountTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            string email = string.Empty; // TODO: Initialize to an appropriate value
            string password = string.Empty; // TODO: Initialize to an appropriate value
            string name = string.Empty; // TODO: Initialize to an appropriate value
            int expected = -1; // TODO: Initialize to an appropriate value
            int actual;
            actual = target.RegisterNewAccount(email, password, name);
            Assert.AreEqual(expected, actual);

            email = "a"; // TODO: Initialize to an appropriate value
            password = string.Empty; // TODO: Initialize to an appropriate value
            name = string.Empty; // TODO: Initialize to an appropriate value
            expected = -1; // TODO: Initialize to an appropriate value
            actual = target.RegisterNewAccount(email, password, name);
            Assert.AreEqual(expected, actual);


            email = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            password = string.Empty; // TODO: Initialize to an appropriate value
            name = string.Empty; // TODO: Initialize to an appropriate value
            expected = -1; // TODO: Initialize to an appropriate value
            actual = target.RegisterNewAccount(email, password, name);
            Assert.AreEqual(expected, actual);

            email = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            password = "only"; // TODO: Initialize to an appropriate value
            name = string.Empty; // TODO: Initialize to an appropriate value
            expected = -1; // TODO: Initialize to an appropriate value
            actual = target.RegisterNewAccount(email, password, name);
            Assert.AreEqual(expected, actual);

            email = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            password = "onlygod@"; // TODO: Initialize to an appropriate value
            name = string.Empty; // TODO: Initialize to an appropriate value
            expected = -1; // TODO: Initialize to an appropriate value
            actual = target.RegisterNewAccount(email, password, name);
            Assert.AreEqual(expected, actual);


            email = "amirpouya.a@gmail.com"; // TODO: Initialize to an appropriate value
            password = "onlygod@"; // TODO: Initialize to an appropriate value
            name = "test"; // TODO: Initialize to an appropriate value
            expected = -1; // TODO: Initialize to an appropriate value
            actual = target.RegisterNewAccount(email, password, name);
            Assert.AreEqual(expected, actual);


            Random random = new Random();
            int randomNumber = random.Next(0, 10000);
            randomNumber = randomNumber + random.Next(10, 100);
            email = "newemaizzl"+randomNumber+"@new.com"; // TODO: Initialize to an appropriate value
            password = "onlygod@"; // TODO: Initialize to an appropriate value
            name = "test"; // TODO: Initialize to an appropriate value
            expected = 10; // TODO: Initialize to an appropriate value
            actual = target.RegisterNewAccount(email, password, name);
            if (actual > 0) actual = 10;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ResetPasswordTest()
        {
            UserControler target = new UserControler(); // TODO: Initialize to an appropriate value
            int id = 4; // TODO: Initialize to an appropriate value
            string Password = "MrrRQi6C018Tb6cps1cHFI0X1t0="; // TODO: Initialize to an appropriate value
             // TODO: Initialize to an appropriate value
            string actual;
            actual = target.ResetPassword(id, Password);
            string expected = target.getAccountData(id).Password;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
